<template>
  <div>
    <el-table
      :data="tableData"
      :header-cell-style="headerStyle"
      :height="height"
      :border="border"
      @selection-change="handleSelectionChange"
    >
      <el-table-column v-if="selection" type="selection" width="55">
      </el-table-column>
      <el-table-column
        v-for="v in tableProp"
        :key="v.label"
        :prop="v.code"
        :sortable="v.sortable"
        :label="v.label"
        :width="v.width"
      >
        <template slot-scope="scope">
          <div v-if="!v.code">
            {{ scope.row[scope.column.property] }}
          </div>
          <div v-else>
            <slot name="row" :row="scope.row"></slot>
          </div>
        </template>
        <el-table-column
          v-for="(item, i) in v.data"
          :key="i"
          :sortable="item.sortable"
          align="center"
          :width="item.width"
          :prop="item.code"
          :label="item.label"
        >
          <template slot-scope="scope">
            <div v-if="!v.code">
              {{ scope.row[scope.column.property] }}
            </div>
            <div v-else>
              <slot name="row" :row="scope.row"></slot>
            </div>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="操作" v-if="ishandle">
        <template slot-scope="scope">
          <slot name="edit" :row="scope.row" :index="scope.$index"></slot>
        </template>
      </el-table-column>
    </el-table>

    <!-- tableData为当前显示的数据，tableProp为表头的名称，可以为多级也可以为单级，区别为data是否存在，headerStyle为表头样式，height为表的高度，sortable以该列为基准的排序，border是否显示边框,handleSelectionChange多选，selection是否显示多选，ishandle是否显示操作，这里使用插槽进行写操作 -->
  </div>
</template>

<script>
export default {
  props: {
    height: {
      type: Number,
      default: 220,
    },
    ishandle: {
      type: Boolean,
      default: false,
    },
    border: {
      type: Boolean,
      default: false,
    },
    tableProp: {
      type: Array,
      default: () => [
        {
          code: "index",
          label: "指标",
          width: 100,
        },
        {
          code: "PAC",
          label: "PAC",
          width: 120,
          data: {
            code: "PAB",
            label: "PAB",
            width: 60,
          },
        },
        {
          code: "PAM",
          label: "PAM",
          width: 60,
          //   code: true,
        },
        {
          code: "POWER_CONSUMPTION",
          label: "综合电耗(kW·h)",
          width: 50,
        },
        {
          code: "WATER_CONSUMPTION",
          label: "自用水率(%)",
        },
      ],
    },
    tableData: {
      type: Array,
      default: () => [
        {
          index: 1,
          PAC: "1",
          PAM: "1",
          POWER_CONSUMPTION: "1",
          WATER_CONSUMPTION: "1",
        },
      ],
    },
    Style: {
      type: String,
      default:
        "font-size: 12px;padding:0;line-height: inherit;font-weight: 500;color: #6A7474;",
    },
  },
  data() {
    return {
      show: false,
    };
  },
  methods: {
    // 样式
    headerStyle() {
      return this.Style;
    },
    // 多选
    handleSelectionChange(val) {
      this.$emit("SelectionChange", val);
    },
  },
};
</script>

<style></style>
